<template>
  <a-form-item :name="props.formNamePath" :label="formItem.label" :rules="[formItem.rule]" :extra="formItem.extra"
    :style="{ marginLeft: formItem.marginLeft + 'px' }" class="form-a-radio-group">
    <date-picker :valueFormat="formItem.valueFormat" :disabled="formItem.disabled" :showTime='formItem.showTime'
      v-model:value="formItem.value" :isNoRange="formItem.isNoRange || false" :disabledInfo="formItem.disabledInfo"></date-picker>
    <div class="help-msg" v-if="formItem.helpMsg">
      {{ formItem.helpMsg }}
    </div>
  </a-form-item>
</template>

<script lang="ts" setup>
import { ref, reactive, watch, computed, nextTick, onMounted, onBeforeMount } from "vue"
import { dataSourceType } from "@/type.d";
import { useColumnItem } from '@/components/draggable/hooks/useColumnModel';
import datePicker from '@/components/picker/dateRangePicker.vue';
import { cloneDeep } from "lodash";
import dayjs from 'dayjs';
import moment from 'moment'
const props = defineProps({
  formItem: {
    type: Object,
    default: {}
  },
  formNamePath: []
})
const formItem: any = ref(props.formItem as any);
useColumnItem(computed(() => props.formItem), formItem)
watch(() => cloneDeep(formItem.value.formSetting), (newVal, oldVal) => {
  nextTick(() => {
    if (formItem.value.value) {
      formItem.value.value = dayjs(formItem.value.value);
    }
    if (formItem.value.unNormal) { // 生日这种日期不能走下面的代码
      return
    }
    let time1 = '';
    time1 = newVal.children[3].value == '3' ? newVal.children[5].value : (newVal.children[3].value == '1' ? newVal.children[4].value : '');
    let time2 = newVal.children[3].value != '1' ? newVal.children[6].value : '';
    formItem.value.valueFormat = time1 + ' ' + time2;
    // if (newVal.children[7].value !== oldVal?.children[7].value) {
    if (newVal.children[7].value && !formItem.value.value) {
      // formItem.value.value = dayjs();

    } else if (!newVal.children[7].value) {
      formItem.value.value = ''
    }
    //}
  })
}, { deep: true });

onBeforeMount(() => {
  if (formItem.value.value) {
    if(formItem.value.param === 'topTime') {
      if(formItem.value.value.startTime) {
        formItem.value.value[0] = dayjs(formItem.value.value.originValue[0]);
        formItem.value.value[1] = dayjs(formItem.value.value.originValue[1]);
      } else {
        formItem.value.value = ""
      }
      
    }else {
      formItem.value.value = dayjs(formItem.value.value);
    }
  } else {
    if(formItem.value.defaultDate && !formItem.value.value && !window.location.href.includes('modelManage')) {
      formItem.value.value = dayjs();
    }
  }
})
</script>

<style lang="less" scoped>
::v-deep(.ant-checkbox-group) {
  display: flex;
}

.help-msg {
  margin-top: 8px;
  font-size: 12px;
  font-family: PingFang SC-Regular, PingFang SC;
  font-weight: 400;
  color: rgba(0, 0, 0, 0.45);
  line-height: 20px;
}
</style>